package com.levy.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import org.junit.Test;
import org.springframework.core.annotation.AnnotationUtils;

public class SpringUtil {
	
	@Test
	public void getAnnotaionBySpringUtil() throws SecurityException, NoSuchMethodException{
		Method method = SuperMan.class.getMethod("getName", null);
		Annotation annotations =  AnnotationUtils.findAnnotation(method, MyAnnotation.class);		
		System.out.println("JDK enhance api:"+annotations);
		
		annotations =  AnnotationUtils.getAnnotation(method, MyAnnotation.class);		
		System.out.println("JDK api:"+annotations);
	}

	
	@Test
	public void getAnnotaionByJDKSuperClass() throws SecurityException, NoSuchMethodException{
		Method method = SuperMan.class.getSuperclass().getMethod("getName", null);
		
		Annotation annotations =  AnnotationUtils.getAnnotation(method, MyAnnotation.class);		
		System.out.println("JDK api with super class:"+annotations);
	}
}
